package com.highcom.model;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration(Configuration.getVersion());
        configuration.setDirectoryForTemplateLoading(new File("C:\\Users\\Administrator\\Desktop"));
        configuration.setDefaultEncoding("utf-8");
        Template template = configuration.getTemplate("freetest.ftl");
        Map map = new HashMap<>();
        map.put("name","张三");
        map.put("message","Freemarker测试");
        map.put("success",true);

        List goodsList = new ArrayList<>();
        Map goods1 = new HashMap<>();
        goods1.put("name","联想");
        goods1.put("price","5000");
        Map goods2 = new HashMap<>();
        goods2.put("name","戴尔");
        goods2.put("price","5000");
        goodsList.add(goods1);
        goodsList.add(goods2);

        map.put("goodsList",goodsList);
        Writer out = new FileWriter(new File("C:\\Users\\Administrator\\Desktop\\test.html"));
        template.process(map,out);
        out.close();
    }
}
